package com.withmiku.world.user.controller;

import com.withmiku.world.user.common.Result;
import com.withmiku.world.user.service.AdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/admin/user")
@PreAuthorize("hasRole('ADMIN')")
public class AdminUserController {
    private final AdminUserService adminUserService;

    @Autowired
    public AdminUserController(@Qualifier("adminUserServiceImpl") AdminUserService adminUserService) {
        this.adminUserService = adminUserService;
    }

    /**
     * 封禁用户
     */
    @PutMapping("/ban/{id}")
    public Result banUser(@PathVariable Long id) {
        adminUserService.updateStatus(id, 0);
        return Result.success(200, "用户已封禁", null);
    }

    /**
     * 解封用户
     */
    @PutMapping("/unban/{id}")
    public Result unbanUser(@PathVariable Long id) {
        adminUserService.updateStatus(id, 1);
        return Result.success(200, "用户已解封", null);
    }
}
